package com.asiainfo.controller;


import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSONObject;
import com.asiainfo.bean.HelperBean;
import com.asiainfo.bean.LiangBean;
import com.asiainfo.bean.MealBean;
import com.asiainfo.bean.UserSessionBean;
import com.asiainfo.dao.BaseDao;
import com.asiainfo.util.DBSequence;
import com.asiainfo.util.SessionInfoUtil;

@Controller
@RequestMapping("/liangController")
public class LiangController extends ModelAndView{

	private Logger logger = LogManager.getLogger(this.getClass());
	
	/**
	 * 数据操作封装DAO
	 */
	@Autowired
	private BaseDao dao;
	
	/**
	 * 方法描述：跳转到套餐列表页面
	 * 
	 * return 套餐列表页面页面Model
	 */
	@RequestMapping("/mealChoiceView.do")
	public ModelAndView mealList() {
		this.setViewName("business/mealChoice");
		return this;	
	}

	
	/*
	 * 
	 * 获得所以订购套餐
	 * 
	 */
	@RequestMapping(value = "/mealChoice.do")
	 
	public @ResponseBody
	JSONObject mealAllowance(@RequestBody MealBean mealBean, 
			HttpServletRequest request) throws Exception {
		JSONObject retMsg = new JSONObject();
		
		UserSessionBean userSessionBean = SessionInfoUtil.getUserSessBean(request.getSession());
		List<MealBean> mealList= new ArrayList<MealBean>();


		
		if(null == userSessionBean)
		{
			logger.error("session 为空时需求重新登录。");
			retMsg.put("flag", false);
		}else
		{
			
			//获得所有可选套餐
			mealList =this.dao.getDAO().selectList(
						"LiangController.mealShow");
			
			
 			retMsg.put("flag", true);
		}
		
		this.addObject("mealList",mealList);
		return retMsg;
		
	}

	
}
